package com.qen.conditions.update;

import com.qen.conditions.AbstractChainWrapper;
import com.qen.interfaces.SFunction;
import com.qen.repository.BaseDao;
import com.qen.wrapper.update.LambdaUpdateWrapper;
import com.qen.wrapper.update.interfaces.UpdateBase;

/**
 * @author licz
 * @data 2025年05月26日 9:54 AM
 */
public class LambdaUpdateChainWrapper<T> extends AbstractChainWrapper<T, SFunction<T, ?>, LambdaUpdateChainWrapper<T>, LambdaUpdateWrapper<T>>
        implements ChainUpdate<T>, UpdateBase<LambdaUpdateChainWrapper<T>, SFunction<T, ?>> {

    private final BaseDao<T> baseDao;

    public LambdaUpdateChainWrapper(BaseDao<T> baseDao) {
        super();
        this.baseDao = baseDao;
        super.wrapperChildren = new LambdaUpdateWrapper<>();
    }

    public LambdaUpdateChainWrapper(Class<T> entityClass) {
        super();
        this.baseDao = null;
        super.wrapperChildren = new LambdaUpdateWrapper<>(entityClass);
    }

    public LambdaUpdateChainWrapper(BaseDao<T> baseDao, LambdaUpdateWrapper<T> wrapperChildren) {
        super();
        this.baseDao = baseDao;
        super.wrapperChildren = wrapperChildren;
    }

    @Override
    public LambdaUpdateChainWrapper<T> set(boolean condition, SFunction<T, ?> column, Object val, String mapping) {
        wrapperChildren.set(condition, column, val, mapping);
        return typedThis;
    }

    @Override
    public LambdaUpdateChainWrapper<T> setSql(boolean condition, String setSql, Object... params) {
        wrapperChildren.setSql(condition, setSql, params);
        return typedThis;
    }


    /**
     * 字段自增变量 val 值
     *
     * @param condition 条件
     * @param column    字段
     * @param val       值
     * @return this
     * @since 1.0.0
     */
    @Override
    public LambdaUpdateChainWrapper<T> setIncrBy(boolean condition, SFunction<T, ?> column, Number val) {
        wrapperChildren.setIncrBy(condition, column, val);
        return typedThis;
    }

    /**
     * 字段自减变量 val 值
     *
     * @param condition 条件
     * @param column    字段
     * @param val       值
     * @return this
     * @since 1.0.0
     */
    @Override
    public LambdaUpdateChainWrapper<T> setDecrBy(boolean condition, SFunction<T, ?> column, Number val) {
        wrapperChildren.setDecrBy(condition, column, val);
        return typedThis;
    }

    @Override
    public BaseDao<T> getBaseDao() {
        return baseDao;
    }

    @Override
    public Class<T> getEntityClass() {
        return super.wrapperChildren.getEntityClass();
    }
}
